<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
request.setCharacterEncoding("UTF-8");
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>交易明细</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<link rel="stylesheet" href="<%=path%>/css/zTreeStyle/zTreeStyle.css">
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=path%>/js/jquery.ztree.excheck-3.5.js"></script>
<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
<style type="text/css">
		#detail
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
        #detail2
        {
            position:relative;
            width: 200px;
            font-size: 12px;
            background: #fff;
            border: 1px solid #000;
            z-index: 2;
            display: none;
        } 
	</style>
	
	<script type="text/javascript">
		var startP = 1;
		$(document).ready(function() {
			loadPrivilegeBranch();
			loadApplicationName();
			//初始读取数据
// 			loadTXLogData();
		});
		var defaultBranchCode="";
		/*  加载权限机构 */
		function loadPrivilegeBranch(){
			$.ajax({
					url : "<%=path%>/transManager/queryPrivilegeBranch",
					type : 'POST',
					async : false,
					dataType:'json',
					success : function(data) {
						if(data){
							if($.validate(data))return;
							//业务处理
							//接口下拉框对象
							var appSelect = document.getElementById("privilegeBranch");
							if (data != null) {
								appSelect.length=0;
								if(data.length>0){
									defaultBranchCode = data[0].deptCode;
								}
								for (var i = 0; i < data.length; i++) {
									var option = new Option();
									option.text = data[i].deptCname;
									option.value = data[i].deptCode;
									option.title = data[i].deptCname;
									appSelect.add(option);
								}
							}
						}
					}
				});
		 }
		//数组去重复
		function unique(arr){
		    var res=[];
		    for(var i=0,len=arr.length;i<len;i++){
		        var obj = arr[i];
		        for(var j=0,jlen = res.length;j<jlen;j++){
		            if(res[j]===obj) break;            
		        }
		        if(jlen===j)res.push(obj);
		    }
		    return res;
		}
		
		function clearObj(){
			$("#instCode").val('');
			var channelTransSelect =  document.getElementById("channelTransSelect");
		/* 	channelTransSelect.options.length = 0; //清空渠道下拉框
			channelTransSelect.add(new Option("--请选择--", "")); */
		}
		/*  加载应用名称 */
		 function loadApplicationName(){
			 	$.ajax({
						url : "transManager/loadTransNameByApplication",
						type : 'POST',
						async : true,
						data: {
						},
						dataType : 'json',
						success : function(obj) {
							//$.closeLoading();
							if($.validate(obj))return;

							var channleTransList=obj.data;
							var list=unique(channleTransList);
	      					var str_channelObj =  document.getElementById("channelApplicationSelect");
	      					str_channelObj.options.length = 0; //清空渠道下拉框
							str_channelObj.add(new Option("--请选择--", ""));
	      					var dataLength = 0;
	      					if(null != list){
	      						dataLength =list.length;
	      					}
	      					var array = new Array(); //定义数组
	      					var array2=null;
	      					for(var i=0;i<dataLength;i++)
	      					{
	      						var txt = channleTransList[i].appname; //获取option的内容      	
	      						array.push(txt); //添加到数组中
	      						array2= unique(array);
	      					}
      						for(var j=0;j<array2.length;j++){
      							var option=new Option();
      							option.text=array2[j];
								option.value=array2[j];
								option.title=array2[j];
								str_channelObj.add(option);
      						}
						}
					}); 
		 }
		
		 /*  加载交易名称 */
		 function loadTransName(application){
		 /* 	var channelCode= $("#instCode").val();
			 	if(channelCode==""){
			 		$.message("error","合作伙伴代码不能为空");
					return;
			 	} */
			 	$.ajax({
						url : "transManager/loadTransNameBychannelCode",
						type : 'POST',
						async : true,
						data: {
						/* 	channel_Code : channelCode, */
							application : application
						},
						dataType : 'json',
						success : function(obj) {
							//$.closeLoading();
							if($.validate(obj))return;

							var channleTransList=obj.data;
	      					var str_channelObj =  document.getElementById("channelTransSelect");
	      					str_channelObj.options.length = 0; //清空渠道下拉框
							str_channelObj.add(new Option("--请选择--", ""));
							//$("#channelTransSelect option:first").title("title",1); 
	      					var dataLength = 0;
	      					if(null != channleTransList){
	      						dataLength =channleTransList.length;
	      					}
	      					for(var i=0;i<dataLength;i++)
	      					{
	      						var option=new Option();
								option.text=channleTransList[i].transName;
								option.value=channleTransList[i].transCode;
								option.title=channleTransList[i].appname;
								str_channelObj.add(option);
	      					}
						}
					}); 
		 }
		 /* 加载初始数据*/
		 function queryTXLogData(displayPage){
			
			var deptCode = $("#privilegeBranch").val();
			var channelCode =  $("#instCode").val();
			var trxDateStr =  $("#operateDate").val();
			var txCodeStr =  $("#channelTransSelect").val(); 
			var applicationCode=$("#channelApplicationSelect").val();
			//alert(txCodeStr+"/"+applicationCode);
			var markStr = $('input:radio[name="searchRadio"]:checked').val();
			var subPartnerNo= $.trim($("#subPartnerNo").val());//合作伙伴子机构
			loadTXLogData({current:displayPage,size:10,channel:channelCode,trxDate:trxDateStr,trxCode:txCodeStr,deptCode:deptCode,mark:markStr,subPartnerNo:subPartnerNo,applicationCode:applicationCode});
		}
		 function showDatail(obj){
				var result=obj.innerHTML;
				if(result!=""){
					 var length =obj.scrollWidth;
					 if(length>240){
					 	var e = arguments.callee.caller.arguments[0]||window.event;
					 	var y = e.clientY;
					 	var x= document.body.offsetWidth;
					 	if(x>460){
					 		x=x-460;
					 	}
					 	var div3 = document.getElementById("detail");   
					 	document.getElementById("detail").style.display = 'block';
					 	div3.style.left=x;     
			            div3.style.top=e.clientY+1;  
			            div3.style.position="absolute";
					 	$("#input")[0].innerHTML=result;
					 }
				}
			}
		 function copyDetail(obj){
				var result=obj.innerHTML;
				if(result!=""){
					 var length =obj.scrollWidth;
					 if(length>0){
					 	var e = arguments.callee.caller.arguments[0]||window.event;
					 	var y = e.clientY;
					 	var x= document.body.offsetWidth;
					 	if(x>460){
					 		x=x-460;
					 	}
					 	var div3 = document.getElementById("detail2");   
	           	 		document.getElementById("detail2").style.display = 'block';
					 	div3.style.left=x;     
			            div3.style.top=e.clientY+1;  
			            div3.style.position="absolute";
					 	$("#output")[0].innerHTML=result;
					 }
				}
			}
		 
		 function closeDatail(){
			 document.getElementById("detail").style.display = 'none';
		 }
		 function closeDiv(){
			 document.getElementById("detail2").style.display = 'none';
	 	 }
		 function vreset(){
			 	$("#privilegeBranch").val(defaultBranchCode);
 				$("#instCode").val('');
				var channelTransSelect =  document.getElementById("channelTransSelect");
				channelTransSelect.options.length = 0; //清空渠道下拉框
				channelTransSelect.add(new Option("--请选择--", ""));
				$("#operateDate").val("");
				$('input:radio[name="searchRadio"]')[0].checked = true;
				//$('input:radio[name="searchRadio"]:checked').val();
				$("#subPartnerNo").val("");
				$("#channelApplicationSelect").val("");
		 }
		 
		 
		 function loadTXLogData(param){
			   var deptCode = $("#privilegeBranch").val();
			   var jsonDate;
			   
				if(null != param && null != param.current){
					var str = "";
					var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
					var trxDate = param.trxDate;
					if(null != trxDate && "" != trxDate){
						if(trxDate.match(strReg)==null){
							$.message("error", "您输入的日期格式不正确，格式为：YYYY-MM-DD");
							return;
						}
					}
					jsonDate =param;
					startP = param.current;
				}else{
					jsonDate={current:1,size:10,deptCode:deptCode};
				}
				
				$.openLoading();
				$.ajax({
						url : "transManager/queryList",
						type : 'POST',
						async : true,
						dataType:'json',
						data:jsonDate,
						success : function(page) {
							$.closeLoading();
							if($.validate(page))return;
						//业务处理
								if(null != page){
									var tableContent = creatTable("channel_Name,trans_Name,msg_Id,operate_Date,total_Elapsed,out_Elapsed,error_Code,<a href='javascript:void(this)' style='font-size:12px;display: block;overflow: hidden;white-space: nowrap;text-align:center;-o-text-overflow: ellipsis;text-overflow: ellipsis;width:120px;font-family:宋体;font-weight:normal' onDblClick='copyDetail(this);' onclick='showDatail(this);return false' onmouseover='showDatail(this);return false' onmouseout='closeDatail(this);return false'>error_Desc</a>",page,null);
									
									var tableObj = $("#gatewayTxLogTable");
									tableObj.find("tbody").remove();
									tableObj.append(tableContent);
									
									var strPage = creatChannelPage(startP,6,page.maxPage,"4");
									var pageDIV = $("#txLogpageDIV");
									pageDIV[0].innerHTML="";
									pageDIV.append(strPage);
								}
							}
					});
			}
		
		//------------------------------------------ 合作伙伴 开始----------------------------------------------
		//initTradPartners
		function queryPartner(param){
			$.openLoading();
			$.ajax({
				url : "transManager/loadChannelInfoByAppid",
				type : 'POST',
				async : true,
				data:param,
				dataType:'json',
				success:function(partnerPage){
					$.closeLoading();
					if($.validate(partnerPage))return;
					var radioObj ="<input class='input_fxk' name='partnerradio' type='radio' value=''>";
					var fieldNames = "channelCode,channelName";
					var tableContent = creatTable1(fieldNames,partnerPage,radioObj);
					var tableObj = $("#TradPartnerTable");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					
					var strPage = creatChannelPage2(param.pageIndex,6,partnerPage.maxPage,"16");
					var pageDIV = $("#TradPartnerPageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
					
					$("#tradPartnerDiv").OpenDiv();
					bindradio();
					}
			});
		}  



		//打开合作伙伴 div 方法
		function openThisDiv(divObj,pageIndex,obj){
			if(($.trim($('#privilegeBranch').val())).length==0){
				$.message('error',"请先选择机构");
				return;
			}
			$('#channelCode').val('');
			$('#channelName').val('');
			$("#"+obj.id).blur();
			queryTradPartners(pageIndex);
		}


		//拼接页面查询参数  查询合作伙伴
		function mergePartnerParams(pageIndex){
			var size = 8;
			var deptCode = $.trim($('#privilegeBranch').val());
			var channelCode = $.trim($('#channelCode').val());
			var channelName = $.trim($('#channelName').val());

			queryPartner({pageIndex:pageIndex,size:size,deptCode:deptCode,channelCode:channelCode,channelName:channelName});
		}



		//查询 合作伙伴
		function queryTradPartners(pageIndex){
			mergePartnerParams(pageIndex);
		}


		//点击“确定”按钮，选择合作伙伴
		function choosePartner(){
			var selectedPartner = $("input[name='partnerradio']:checked");
			if(selectedPartner.length==0){
				$.message("error", "请选择一个合作伙伴");
				return;
			}
			var pno = selectedPartner.parent().parent().children(" td:eq(1)").html();
			$('#instCode').val(pno);
			
			closeCurrentDIV('tradPartnerDiv');
			//loadTransName();
/* 			loadApplicationName();//查询应用信息 */
		}
		//------------------------------------------ 合作伙伴 结束----------------------------------------------
		//统一 关闭  窗口
	function closeCurrentDIV(obj){
			$("#"+obj).CloseDiv();	
	}
			
	//绑定单选按钮事件，选中某个单选按钮，该按钮所在行高亮显示
	function bindradio(){
		$("input[name='partnerradio']").click(function(){
			$("input[name='partnerradio']").parent().parent().removeClass("table_highlighter");
			$(this).parent().parent().addClass("table_highlighter");
	   	});
	}
	
	//------------------------------------------ 合作伙伴子机构 开始----------------------------------------------
	//加载subChannelTree
	function openSubChannelTreeDiv(){
		var partnerNo = $.trim($('#instCode').val());
		if(partnerNo.length==0){
			$.message("error", "请先选择合作伙伴");
			return;
		}
		
		$.openLoading();
		$.ajax({
			url : "<%=path%>/transManager/querySubChannelTree?"+new Date().getTime(),
			type : 'POST',
			async : true,
			data:{
				parentChannelCode:partnerNo
			},
			dataType:'json',
			success:function(data){
				$.closeLoading();
				if($.validate(data))return;
				
				if(data.length == 0){
					$.message("error", "所选合作伙伴下没有合作伙伴子机构");return;
				}
				var setting = {
						check: {
							enable: true,
							chkStyle: "radio",
							radioType: "all"
						},
						data: {
							simpleData: {
								enable: true
							}
						}
					};

				$.fn.zTree.init($("#subChannelTree"), setting, data);
				
				$("#subChannelTreeDiv").OpenDiv();
			}
		});
	}
	
	//点击“确定”按钮，选择合作伙伴子机构
	function chooseSubPartner(){
		var subChannelTree = $.fn.zTree.getZTreeObj("subChannelTree");
		if(subChannelTree.getCheckedNodes(true).length==0){
			$.message("error", "请选择一个合作伙伴子机构");
			return;
		}
		var subChannels = subChannelTree.getCheckedNodes(true);
		$("#subPartnerNo").val(subChannels[0].id);
		
		closeCurrentDIV('subChannelTreeDiv');
	}
	
	//应用改变
	function  changeApplication(){
		var  application= $("#channelApplicationSelect option:selected").val();
		loadTransName(application);
	} 
	
	
	</script>
 </head>
<body>
<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">统计分析
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>交易明细
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
</div>
		<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="50px">
							<td width="10%" height="30" style="text-align: right;">机构：</td>
							<td width="10%" height="30" style="text-align: left;">
								<select class="search_select_1" id="privilegeBranch" style="width: 220px;" onchange="clearObj()">
					            	<option value="">--请选择--</option>
								</select>
							</td>
							<td width="10%" height="30" style="text-align: right;">合作伙伴：</td>
							<td width="25%" height="30" style="text-align: left;">
								<input name="instCode" id="instCode" type="text" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5"  id="searchPartnerBtn" value="请选择" onClick="openThisDiv('tradPartnerDiv',1,this)"/>
							</td>
							<td width="10%" height="30" style="text-align: right;">合作伙伴子机构：</td>
		                    <td width="25%" height="30" style="text-align: left;"><input name="partnerSubCode" id="subPartnerNo" readonly="readonly" style=" background-color: #ccc;" class="input_text">&nbsp;&nbsp;<input type="button"  class="input_button_5"  id="searchSubPartnerBtn" value="请选择" onClick="openSubChannelTreeDiv()"/></td>
						</tr>
						<tr>
							<td width="10%" height="30" style="text-align: right;">应用：</td>
							<td width="20%" height="30" style="text-align: left;">
								<select  class="search_select_1" id="channelApplicationSelect" onchange="changeApplication()" >
									<option value="">--请选择--</option>
								</select>
							</td>
							<td width="10%" height="30" style="text-align: right;">交易名称：</td>
							<td width="20%" height="30" style="text-align: left;">
								<select  class="search_select_1" id="channelTransSelect" >
									<option value="">--请选择--</option>
								</select>
							</td>
							<td width="10%" height="30" style="text-align: right;">交易日期：</td>
							<td width="20%" height="30" style="text-align: left;">
								 <input id="operateDate"  onkeydown="false"  onclick="showCalendar('operateDate','y-mm-dd');"  class="input_time"  type="text" />
							</td>
						</tr>
						<tr>
							<td width="10%" height="30" style="text-align: right;">结果类型：</td>
							<td width="60%" height="30" style="text-align: left;" colspan="2">
								<input type="radio" name="searchRadio" value="" checked="checked" />所有 
								<input type="radio" name="searchRadio" value="1" />成功 
								<input type="radio" name="searchRadio" value="0" />失败
							</td>
						
						</tr>
						<tr>
							<td style="text-align: center;" colspan="5" width="100%" height="30">
							  <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTXLogData(1)"/>&nbsp;
							  <input type="button"  class="input_button_1" id="searchBtn" value="重置" onClick="vreset()"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td valign="top">
		  			<div id="transDiv" style="width:98%;margin:5px" >
					<table id="gatewayTxLogTable"  class="table_02" >
						<thead>
							<tr>
								<th style="width:19%">合作伙伴</th>
								<th style="width:10%">交易名称</th>
								<th style="width:18%">交易流水号</th>
								<th style="width:13%">交易时间</th>
								<th style="width:8%">总耗时（秒）</th>
								<th style="width:10%">核心耗时（秒）</th>
								<th style="width:7%">结果代码</th>
								<th style="width:15%">结果描述</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txLogpageDIV"  class="page"></div>
				   </div>
				</td>
			</tr>
		</table>
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		<div id="detail" style="display:none;">
			<div id="input" style="margin:5px;word-wrap:break-word;"></div>
		</div>
		<div id="detail2" style="display:none;">
			<h4  style='background-color:#A4BDE3;'>
				<table height="20px">
					<tr>
					    <td width="200px";>
					    </td>
					    <td align="right">
					       <img src="./images/closedown.gif"  onclick="closeDiv()"/>
					    </td>
					</tr>							
				</table>
				<input type="hidden" id="appId" value="">
			</h4>	
			<div id="output" style="margin:5px;word-wrap:break-word;"></div>
		</div>
		<!--选择 合作伙伴 div-->
  		<div id="tradPartnerDiv" style="display:none;width:80%;">
  		<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="./images/closedown.gif" alt="关闭"  onclick="closeCurrentDIV('tradPartnerDiv')"/></td>
						</tr>
					</table>
			</div>
		<table class="table_02" id="table" style="height:180px;" align="center">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td colspan="3" style="text-align:center">
							 合作伙伴代码：<input name="txt3"  id="channelCode"  type="text" class="input_text" value="" >&nbsp;&nbsp;
							 合作伙伴名称：<input name="txt3" id="channelName"  type="text" class="input_text" value="">&nbsp;&nbsp;
								       <input type="button"  class="input_button_1" id="searchBtn" value="查询" onClick="queryTradPartners(1)"/>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="TradPartnerTable"  class="content_table_1">
						<thead>
							<tr class="f1">
			                  <th style="width:5%">选择</th>
			                  <th style="width:10%">合作伙伴代码</th>
			                  <th style="width:20%">合作伙伴名称</th>
			              	</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="TradPartnerPageDIV"  class="page"></div>
				</td>
			</tr>
		</table>
		<div align="center" >
		  <input type="button" id="saveRoleBtn" value="确定" onclick="choosePartner()" class="input_button_3"/>&nbsp;&nbsp;&nbsp;
		  <input type="button" value="取消" onclick="closeCurrentDIV('tradPartnerDiv')" class="input_button_3"/>
		</div>
	</div>
	<%--subChannelTree(选择合作伙伴子机构层) --%>
    <div id="subChannelTreeDiv" style="display: none;width:500px;margin-top: -50px" align="center">
    	<div class="table_title_div">
			<table class="table_title" style='width:500px; height: 20px;'>
				<tr>
					<td width="10%"></td>
					<td width="80%" id="interfaceName"></td>
					<td width="10%" align="right"><img src="<%=path %>/images/closedown.gif" alt="关闭"  onclick="closeChannelTreeDiv()"/></td>
				</tr>
			</table>
		</div>
		
		<div style="height: 300px;width:500px; overflow:auto">
			<ul id="subChannelTree" class="ztree"></ul>
		</div>
		
		<div style="text-align: center;padding: 5px">
			<input type="button" id="choseChannelBtn" value="确定" onclick="chooseSubPartner()" class="input_button_1"/>&nbsp;&nbsp;&nbsp;
			<input type="button" value="取消" onclick="closeCurrentDIV('subChannelTreeDiv')" class="input_button_1"/>
		</div>
	</div>
</body>
</html>
